<template>
	<view class="page-news">
		<!-- <refresh :display="refreshing" @refresh="onrefresh" @pullingdown="onpullingdown"></refresh> -->
		<scroll-view class="listview" style="flex: 1;" enableBackToTop="true" scroll-y @scrolltolower="loadData()">
			<cell v-for="(item, index) in pageData.dataList" :key="item.id">
				<news-item :newsItem="item" @click="goDetail(item)"></news-item>
			</cell>
			<cell v-if="pageData.isLoading || pageData.dataList.length > 4">
				<view class="loading-more">
					<text class="loading-more-text">{{loadingText}}</text>
				</view>
			</cell>
		</scroll-view>
	</view>

</template>
<script setup>
	import biznewcontentapi from '@/api/biz/biz-newcontent-api.js'
	import newsItem from "./item.vue"
	import {
		reactive
	} from 'vue';
	import {
		friendlyDate
	} from '@/common/util.js';

	import uniLoadMore from '@/components/uni-load-more.vue';
	import noData from '@/components/nodata.nvue';
	const props = defineProps({
		nid: {
			type: String,
			default: '',
			required: false
		},
	})
	const pageData = reactive({
		dataList: [],
		current: 1,
		size: 10,
		navigateFlag: false,
		pulling: false,
		refreshing: false,
		refreshFlag: false,
		refreshText: "",
		isLoading: false,
		loadingText: '加载中...',
		isNoData: false,
		pulling: false,
		angle: 0,
		loadingMoreText: {
			contentdown: '',
			contentrefresh: '',
			contentnomore: ''
		},
		refreshIcon: ""
	})


	const loadData = (refresh) => {
		if (refresh) {
			pageData.current = 1
			pageData.dataList = []

		} else {
			pageData.current = pageData.current + 1
		}
		biznewcontentapi.newColumnListAll({
			size: pageData.size,
			current: pageData.current,
			columnId: props.nid
		}).then(res => {
			pageData.dataList.push(...res.records)

		})
	}
	// 查看新闻详情
	const goDetail = (item) => {
		uni.navigateTo({
			url: '/pages/home/news/detail?query=' + item.id
		});
	}
	defineExpose({
		loadData
	})
</script>


<style scoped>
	.no-data {
		flex: 1;
		position: absolute;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		z-index: 10;
	}

	.page-news {
		flex: 1;
		flex-direction: column;
		position: absolute;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
	}

	.listview {
		position: absolute;
		left: 0;
		top: 0;
		right: 0;
		bottom: 0;
		/* #ifndef APP-NVUE */
		display: flex;
		flex-direction: column;
		/* #endif */
		/* #ifndef MP-ALIPAY */
		flex-direction: column;
		/* #endif */
	}

	.refresh {
		justify-content: center;
	}

	.refresh-view {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		width: 750rpx;
		height: 64px;
		flex-direction: row;
		flex-wrap: nowrap;
		align-items: center;
		justify-content: center;
	}

	.refresh-icon {
		width: 32px;
		height: 32px;
		transition-duration: .5s;
		transition-property: transform;
		transform: rotate(0deg);
		transform-origin: 15px 15px;
	}

	.refresh-icon-active {
		transform: rotate(180deg);
	}

	.loading-icon {
		width: 28px;
		height: 28px;
		margin-right: 5px;
		color: gray;
	}

	.loading-text {
		margin-left: 2px;
		font-size: 16px;
		color: #999999;
	}

	.loading-more {
		align-items: center;
		justify-content: center;
		padding-top: 14px;
		padding-bottom: 14px;
		text-align: center;
	}

	.loading-more-text {
		font-size: 28upx;
		color: #999;
	}
</style>